Release 10.1A: OpenEdge Development:
Programming Interfaces
Using editing blocks and user interface triggers
Note:EDITINGblocks are a deprecated feature. Prior to event-driven programming, ChUI procedural applications usedEDITINGblocks.EDITINGblocks are not appropriate for event-driven, multi-tier, or Service-Oriented applications. Use theWAIT-FORstatement to replaceEDITINGblocks.This procedure uses an
EDITINGblock on theUPDATEstatement to enable a special key while allowing normal data entry:
The
EDITINGblock processes every keystroke the user enters while thatUPDATEstatement is executing. Within theEDITINGblock, theREADKEYstatement reads a keystroke from the user. The associated key code is automatically stored asLASTKEY. The procedure usesLASTKEYand theFRAME–FIELDfunction to determine whether the key is F6, and whether it was entered from within the Sales–rep field. If so, it displays a list of all known sales reps. If the key is not F6, or the current field is not the Sales–rep field, then theAPPLYstatement is executed. This causes Progress to handle the keystroke normally.This procedure uses a user interface trigger in place of the
EDITINGblock to achieve the same functionality:
Use a trigger in place of the
EDITINGblock to produce simpler, cleaner code. It would be easier to rewrite this code to be more event driven. First, replace theUPDATEstatement withENABLE,WAIT–FOR, andASSIGN. You then might remove theREPEATblock and define a button that the user can select to move to the next Customer record. You might also replace the display of sales reps with a selection list or browse widget.The following procedure uses an
EDITINGblock to disallow normal data entry on a field and allow only a special key:
Like
i-kystka.p, this procedure uses anEDITINGblock on theUPDATEstatement. In theEDITINGblock, it usesREADKEY,LASTKEY, andFRAME–FIELDto obtain and analyze a keystroke. If the keystroke is not in the Sales–rep field, it is processed normally. Within the Sales–rep field, only the spacebar is treated specially and only theTAB,BACK–TAB,GO, andEND–ERRORkey functions are treated normally. If the user types any other key within the field, the terminal bell sounds. When the user presses the spacebar in the Sales–rep field, the value of that field and the Sales–region field change.The following procedure uses triggers to accomplish the same thing:
Note the use of
RETURN NO–APPLYin both theANY–PRINTABLEand spacebar trigger. This is equivalent to omitting theAPPLY LASTKEYstatement in anEDITINGblock. Thus, the spacebar trigger brings the next Sales–rep into view, without also inserting a space character in the field.Note also that in
i-kystk2.ptheANY–PRINTABLEtrigger rejects all keys that enter data characters other than a space. This works together with the spacebar trigger to allow only the spacebar and navigation keys (TAB, etc.) in the field.Sometimes an
EDITINGblock defines a special key that applies for all active fields:
In
i-kystk3.p, theEDITINGblock defines a special key, F6, that is available in all fields of theUPDATEstatement. When the user presses this key, the previous Customer record displays.The following procedure uses a trigger to achieve the same result:
If you define a trigger to be active
ANYWHERE, then it applies to all widgets. Ini-kystk4.p, the F6 trigger executes whenever the user presses F6 while input is enabled. Within the trigger, theFRAME–FIELDfunction determines whether the t rigger executes from theUPDATEorPROMPT–FORstatement. If it is thePROMPT–FORstatement, then F6 is ignored; if it is theUPDATEstatement, the previous Customer record displays.In a larger program, be careful of the scope of the
ANYWHEREtrigger. You are usually better off listing the specific widgets to which a trigger applies. For example, you could rewrite the ON statement ini-kystrk4.pas follows:
If you take this approach, you can remove the code that checks whether
FRAME–FIELDis Cust–num within the trigger.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |